<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 不使用apply方法绑定上下文，使用ES6语法 

        //防抖
        function debounce(fn, delay = 500) {
            // timer 是闭包中的
            let timer = null
            return (...args) => {
                clearTimeout(timer)
                timer = setTimeout(() => {
                    fn(...args)
                }, delay)
            }
        }
        // 节流
        function throttle(fn, delay = 100) {
            let timer = null
            return (...args) => {
                if (timer) {
                    return
                }
                timer = setTimeout(() => {
                    fn(...args)
                    timer = null
                }, delay)
            }
        }
    </script>
</body>

</html>